home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / runtime / mac / os_mac_eKeys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  3.4 KB  |  116 lines

  1. /* os_mac_eKeys.c
  2.  * 3May92  e
  3.  */
  4.  
  5. #include "os_mac_eEdit.h"
  6.  
  7. /* extensions to an editor for text files by e
  8.    questions/comments via Internet <e@Flavors.COM> */
  9. /* Copyright ⌐ e, 1989,1992. All rights reserved.
  10.     Developed using THINK C 5.0.1 for use with Gambit Scheme.
  11.     This code may be freely distributed as long as this notice remains.
  12.    thanks to Marc Feeley.
  13. */
  14.  
  15. #define whsp_char(c) (((c)>=0) && ((c)<=32))
  16.  
  17. /* 16Dec92  e  -- miniature version of os_mac_eKeys.c for ML */
  18.  
  19. /* <tab> documentation
  20.  * C1 is the position of the first graphic character on the current line
  21.  * P1 is the position of the first graphic character on the previous line
  22.  * <option-tab>
  23.  *   inserts or removes space on the current line to align C1 with P1
  24.  * <tab>
  25.  *   if C1 < P1 then same as <option-tab>
  26.  *              else insert sufficient space on the current line
  27.  *                   to move C1 right to next tab stop
  28.  * <shift-tab>
  29.  *   if C1 > P1 then same as <option-tab>
  30.  *              else remove sufficient space on the current line
  31.  *                   to move C1 left to previous tab stop
  32.  * Notes: 
  33.  *  <tab> does not move the insert point or selection relative to the text
  34.  *  <tab> characters are never inserted into the text
  35.  */
  36.  
  37. extern short check_TEInsert( char *ptr, long len, eRec **hE, short bold );
  38.  
  39. static char *eighty = "                                                                                ";
  40.  
  41. void eTabCommand( eRec **hE, short modifiers, short style )
  42. { long open_paren;
  43.   long selStart, selEnd, selLen;
  44.   ChPos plcp, tlcp, nlcp;
  45.   char *p;
  46.   long pl, tl, nl;
  47.   long adj = 0;
  48.   Boolean selActive;
  49.  
  50.   if( ( selActive = (**hE).selActive ) )
  51.   {    selStart = eTeChPosToOffset( hE, (**hE).selStart );
  52.     selEnd   = eTeChPosToOffset( hE, (**hE).selEnd );
  53.     selLen   = selEnd - selStart;
  54.     eTeSetSelect( hE, selStart, selStart );
  55.     tlcp = (**hE).selStart;
  56.   }
  57.   else
  58.   {    selStart = eTeChPosToOffset( hE, (**hE).caretChPos );
  59.     selLen = 0;
  60.     tlcp = (**hE).caretChPos;
  61.   }
  62.   plcp.h = tlcp.h = nlcp.h = 0;    /* start of {prev,this,next} line */
  63.   plcp.v = tlcp.v - 1;
  64.   nlcp.v = tlcp.v + 1;
  65.   nl = eTeChPosToOffset( hE, nlcp );    /* next line */
  66.   tl = eTeChPosToOffset( hE, tlcp );    /* this line */
  67.   if (plcp.v < 0)
  68.   {    pl = 0;
  69.       plcp.v = 0;
  70.   }
  71.   else
  72.   { pl = eTeChPosToOffset( hE, plcp );
  73.     p = *((**hE).hText) + pl;
  74.     while( whsp_char( *p ) && pl < tl && *p != RETURN ) { p++; pl++; plcp.h++; }
  75.   }
  76.   p = *((**hE).hText) + tl;
  77.   while( whsp_char( *p ) && tl < nl && *p != RETURN ) { p++; tl++; tlcp.h++; }
  78.  
  79.   if( tl != selStart ) eTeSetSelect( hE, tl, tl );
  80.   if( tl < selStart )  adj = selStart - tl;
  81.   
  82.   if ( ! ( modifiers & optionKey ) )
  83.   {    short tabStops = (**hE).tabStops;
  84.     if( modifiers & shiftKey )
  85.     { if( tlcp.h <= plcp.h )
  86.         if( tlcp.h > 0 && tabStops > 0 )
  87.             plcp.h = ( (tlcp.h - 1) / tabStops ) * tabStops;
  88.         else
  89.             plcp.h = 0;
  90.     }
  91.     else
  92.     { if( tlcp.h >= plcp.h && tabStops > 0 )
  93.         plcp.h = tlcp.h + tabStops - tlcp.h % tabStops;
  94.     }
  95.   }
  96.   if( tlcp.h > plcp.h )
  97.   { plcp.v = tlcp.v;
  98.     pl = eTeChPosToOffset( hE, plcp );
  99.     eTeSetSelect( hE, pl, pl );
  100.     eTeKillTo( hE, tlcp );
  101.   }
  102.   else while (tlcp.h < plcp.h)
  103.   { long len = (plcp.h - tlcp.h < 80) ? plcp.h - tlcp.h : 80;
  104.     if (check_TEInsert( eighty, len, hE, style )) goto err;
  105.     tlcp.h += len;
  106.   }
  107.   err:
  108.   if( tl < selStart || selActive )
  109.   { selStart = eTeChPosToOffset( hE, (**hE).caretChPos ) + adj;
  110.     eTeSetSelect( hE, selStart, selStart + selLen );
  111.   }
  112.   eTeShowCaret( hE );
  113. }
  114.  
  115. /* end of os_mac_eKeys.c */
  116.